package com.ruoyi.web.controller.activiti;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.activiti.domain.SpecialCaseHandling;
import com.ruoyi.activiti.service.ISpecialCaseHandlingService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 特殊情况处理Controller
 * 
 * @author lifan
 * @date 2021-04-14
 */
@Controller
@RequestMapping("/activiti/handling")
public class SpecialCaseHandlingController extends BaseController
{
    private String prefix = "activiti/handling";

    @Autowired
    private ISpecialCaseHandlingService specialCaseHandlingService;

    @RequiresPermissions("activiti:handling:view")
    @GetMapping()
    public String handling()
    {
        return prefix + "/handling";
    }

    /**
     * 查询特殊情况处理列表
     */
    @RequiresPermissions("activiti:handling:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SpecialCaseHandling specialCaseHandling)
    {
        startPage();
        List<SpecialCaseHandling> list = specialCaseHandlingService.selectSpecialCaseHandlingList(specialCaseHandling);
        return getDataTable(list);
    }

    /**
     * 导出特殊情况处理列表
     */
    @RequiresPermissions("activiti:handling:export")
    @Log(title = "特殊情况处理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SpecialCaseHandling specialCaseHandling)
    {
        List<SpecialCaseHandling> list = specialCaseHandlingService.selectSpecialCaseHandlingList(specialCaseHandling);
        ExcelUtil<SpecialCaseHandling> util = new ExcelUtil<SpecialCaseHandling>(SpecialCaseHandling.class);
        return util.exportExcel(list, "handling");
    }

    /**
     * 新增特殊情况处理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存特殊情况处理
     */
    @RequiresPermissions("activiti:handling:add")
    @Log(title = "特殊情况处理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SpecialCaseHandling specialCaseHandling)
    {
        return toAjax(specialCaseHandlingService.insertSpecialCaseHandling(specialCaseHandling));
    }

    /**
     * 修改特殊情况处理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SpecialCaseHandling specialCaseHandling = specialCaseHandlingService.selectSpecialCaseHandlingById(id);
        mmap.put("specialCaseHandling", specialCaseHandling);
        return prefix + "/edit";
    }

    /**
     * 修改保存特殊情况处理
     */
    @RequiresPermissions("activiti:handling:edit")
    @Log(title = "特殊情况处理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SpecialCaseHandling specialCaseHandling)
    {
        return toAjax(specialCaseHandlingService.updateSpecialCaseHandling(specialCaseHandling));
    }

    /**
     * 删除特殊情况处理
     */
    @RequiresPermissions("activiti:handling:remove")
    @Log(title = "特殊情况处理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(specialCaseHandlingService.deleteSpecialCaseHandlingByIds(ids));
    }
}
